# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=ormolu
pkgver=0.7.4.0
pkgrel=1
pkgdesc="Formatter for Haskell source code"
url="https://github.com/tweag/ormolu"
arch="x86_64 aarch64" # limited by ghc
license="BSD-3-Clause"
makedepends="ghc cabal"
options="net"
subpackages="$pkgname-doc"
source="https://hackage.haskell.org/package/ormolu-$pkgver/ormolu-$pkgver.tar.gz
	cabal.project.freeze"

# Directory were cabal files are stored.
export CABAL_DIR="$srcdir/dist"

# Needed to fix build on aarch64.
export PATH="$PATH:/usr/lib/llvm15/bin"

cabal_update() {
	cd $builddir
	cabal v2-update
	(
		cd "$builddir"
		cabal v2-freeze --shadow-installed-packages
		mv cabal.project.freeze "$startdir/"
	)
}

prepare() {
	default_prepare
	ln -sf "$srcdir/cabal.project.freeze" \
		"$builddir/cabal.project.freeze"
}

build() {
	cabal v2-update
	cabal v2-build ormolu:exes \
		--jobs=${JOBS:-1} \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--sysconfdir=/etc
}

check() {
	cabal test
}

package() {
	# See https://github.com/haskell/cabal/issues/6919#issuecomment-761563498
	cabal list-bin ormolu:exes | xargs install -Dm755 -t "$pkgdir"/usr/bin

	# Install some docmuentation files
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGELOG.md DESIGN.md \
		"$pkgdir"/usr/share/doc/$pkgname
}

sha512sums="
2e5ec2b4a47ffb4e31c4461cbc4812b72a754b5dac32dc0ceedfdd780d1dfc5720f9e61bdb05f38936405603368ed7ea75b4d804254f31db43e0ab26c6d7a2c2  ormolu-0.7.4.0.tar.gz
7170457f9a998fc61c03209bd032b30c78f3267c77ae960239359666cb68451095e4dd311cfbdbdf3293a38066fcdc30d34149aef3cba711492c3a7b3924bc9d  cabal.project.freeze
"
